use "C:\Users\ibo6\OneDrive - The Pennsylvania State University\Working Papers\Target Hardening\v10 Terrorism and Political Violence\R & R\Analysis\rdyads2.dta", replace

* TABLE 4
** Model 8: Instate attacks (simple)
nbreg instate b_l str_intel_log_l total_l, robust cluster(dyadid)
estimates store t3_instate_simple

** Model 9: Instate attacks (extended)
nbreg instate b_l str_intel_log_l total_l suictot_l coin_deaths_log_l inten epr ib2.ideology, robust cluster(dyadid)
estimates store t3_instate_extended

ssc install estout
label variable b_l "Success rate of instate attacks (lagged)"
label variable total_l "Total number of attacks (lagged)"
label variable str_intel_log_l "Hardening (lagged)"
label variable a_l "Success rate against hard targets (lagged)"
label variable suictot_l "Ratio of suicide attacks (lagged)"
label variable coin_deaths_log_l "COIN casualties (lagged)"
label variable inten "Conflict intensity"
label variable epr "Ethnic fractionalization"
label variable ideology "Group ideology"

label define ideology 1 "Ethnonationalist" 2 "Religious" 3 "Leftist" 4 "Other"
label values ideology ideology

esttab t3_instate_simple t3_instate_extended using table4.csv, b(%5.3f)  mlabel("Instate" "Instate" "Instate") se starlevels(* 0.1 ** 0.05 *** 0.01) label noconstant nobaselevels title("Negative Binomial Models of Instate Target Selection in Relevant State-Group Dyads in India, 2004-2016") addnotes("The dependent variables are the number of instate attacks committed in a given relevant state-group dyad in a given year. An attack is coded as an instate attack if the state where the attack occurred is the primary area of operation of the group perpetrating the attack. Robust standard errors clustered on relevant state-group dyads are presented in parentheses.")




* FIGURE 7:  Interaction of success rate in instate attacks and ideology
** Panel A-B-C-D
estimates restore t3_instate_extended
* Ethno-nationalist
margins, at(b_l=(0(0.1)1) str_intel_log_l=6.20 total_l=4 suictot_l=0 coin_deaths_log_l=0.73 inten=0 epr=4.91 ideology=1)
* Religious
estimates restore t3_instate_extended
margins, at(b_l=(0(0.1)1) str_intel_log_l=6.20 total_l=5 suictot_l=0 coin_deaths_log_l=0.73 inten=0 epr=4.91 ideology=2)
* Leftist
estimates restore t3_instate_extended
margins, at(b_l=(0(0.1)1) str_intel_log_l=6.20 total_l=5 suictot_l=0 coin_deaths_log_l=0.73 inten=0 epr=4.91 ideology=3)
* Together
margins, at(b_l=(0(0.1)1) str_intel_log_l=6.20 total_l=4 suictot_l=0 coin_deaths_log_l=0.73 inten=0 epr=4.91 ideology=(1(1)4))
marginsplot, noci recast(line) plot1opts(lpattern(solid) color(black) lwidth(medthick)) plot2opts(lpattern(dash) color(black) lwidth(medthick)) plot3opts(lpattern(shortdash) color(black) lwidth(medthick)) plot4opts(lpattern(longdash) color(black) lwidth(medthick)) title("") ytitle("Predicted number of instate attacks") xtitle("Past success rate of in-state attacks") ylabel(0(0.5)3.5) xlabel(0(0.2)1) legend(forces size(small))
name(figure7, replace)




